/**
 * Author: w景洋.
 * Time: 2016/6/15 0015
 */
angular.module('mall.detail', [

])
.config(['$stateProvider',  '$urlRouterProvider',
    function($stateProvider, $urlRouterProvider) {
        $stateProvider

            .state('detail', {
                url: '/detail/:shopid/:goodsid',
                templateUrl: cmt_mall_templateprefix+'/detail/detail.html',
                resolve:{
                    shopinfo: ['$stateParams','ShopService',function($stateParams,ShopService){
                        var shopinfo = ShopService.queryShopByShopid($stateParams.shopid);
                        if (shopinfo.$promise) {
                            return shopinfo.$promise;
                        }
                        return shopinfo;
                    }]
                },
                controller: 'GoodsDetailController'
            })
    }
])

// 
.controller('GoodsDetailController', ['$scope','$stateParams','ShopcartService','ShopMenuService' ,'GoodsService','shopinfo',
    function($scope, $stateParams, ShopcartService,ShopMenuService,GoodsService,shopinfo) {
        $scope.goodsid = $stateParams.goodsid;
        /*click_show(".descirption_btn",".description_buy","#hidval");*/
        GoodsService.getGoodsByGoodsId($scope.goodsid).$promise.then(function (data) {
            $scope.good = data;
            $scope.good.buycount = ShopcartService.getBuycountByGoodsid(data.shopid, data.cataid, data.goodsid);
            console.log(data)
        });
        $scope.shopid = $stateParams.shopid;
        $scope.shopname = shopinfo.name;
        $scope.add = function (cataid, goodsid) {
            ShopcartService.addgoods($scope.shopid, cataid, goodsid);
            $scope.good.buycount = ShopcartService.getBuycountByGoodsid($scope.good.shopid, $scope.good.cataid, $scope.good.goodsid);
        }

        $scope.remove = function (cataid, goodsid) {
            ShopcartService.removeGoods($scope.shopid, cataid, goodsid);
            $scope.good.buycount = ShopcartService.getBuycountByGoodsid($scope.good.shopid, $scope.good.cataid, $scope.good.goodsid);
        }
        $scope.buy_change = function (cataid, goodsid) {
            ShopMenuService.inputChange($scope.shopid, cataid, goodsid);
            ShopcartService.importGoods($scope.shopid, cataid, goodsid);
        }
        $scope.input = function (cataid, goodsid) {
            ShopMenuService.inputBlur($scope.shopid, cataid, goodsid)
            ShopcartService.importGoods($scope.shopid, cataid, goodsid);
        }
    }
])
;
